package cn.lix.sc.rpc.eureka.listener;

import org.springframework.cloud.netflix.eureka.server.event.*;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class EurekaStateChangeListener {

    private final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(this.getClass());

    @EventListener
    public void listen(EurekaInstanceCanceledEvent eurekaInstanceCanceledEvent) {
        //服务断线事件
        log.info("实例断开事件-AppName:" + eurekaInstanceCanceledEvent.getAppName());
    }

    @EventListener
    public void listen(EurekaInstanceRegisteredEvent event) {
        log.info("实例注册活动-InstanceInfo:" + event.getInstanceInfo().getAppName());
    }

    @EventListener
    public void listen(EurekaInstanceRenewedEvent event) {
        log.info("实例续订事件-AppName:" + event.getAppName());
    }

    @EventListener
    public void listen(EurekaRegistryAvailableEvent event) {
        log.info("注册表可用事件-Timestamp:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date(event.getTimestamp())));
    }

    @EventListener
    public void listen(EurekaServerStartedEvent event) {
        log.info("Eureka Server启动事件-Timestamp:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date(event.getTimestamp())));
    }
}